package com.supervision.manage.service

import com.fly.base.misc.pagination.Pagination
import com.supervision.domain.bean.po.CourtOrgSearchPO
import com.supervision.domain.model.CourtOrg
import com.supervision.manage.mapper.CourtOrgMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service("CourtOrgService")
class CourtOrgService {

    companion object {
        private val logger = org.slf4j.LoggerFactory.getLogger(CourtOrgService::class.java)
    }

    @Autowired
    lateinit var courtOrgMapper: CourtOrgMapper

    fun select(condition: CourtOrg, otherCondition: String?): List<CourtOrg> {
        return courtOrgMapper.select(condition, otherCondition)
    }

    fun getCourtOrgList(po: CourtOrgSearchPO): HashMap<String, Any> {
        val list = courtOrgMapper.getCourtOrgList(po, Pagination.limitSql(po.page, po.pageSize))
        val count = courtOrgMapper.countCourtOrgList(po, "")

        return hashMapOf<String, Any>(
                "list" to list,
                "count" to count
        )
    }

    fun save(po: CourtOrg) {
        val courtOrg = CourtOrg.findById(po.id) ?: CourtOrg()

        courtOrg.name = po.name
        courtOrg.province = po.province
        courtOrg.city = po.city
        courtOrg.county = po.county
        courtOrg.address = po.address
        courtOrg.save()
    }
}
